<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$item=$this->plugin_setting('setting');
if($_RQ['op']=='main'){
	$info=pdo_get('jy_daijia_driver',array('mid'=>$_SESSION['uid']));
	if($info&&$info['status']==0){
			exi('您的申请正在审核，请耐心等待','','/index/');
	}
	if($info&&$info['status']==1){
			//exi('您已经申请成为司机，无需重复申请','','/index/'); 
	}
	$info['sex']=$info['sex']?:1;
	$info['codeimg']=json_decode($info['codeimg'],true);
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$info['avatar']=$info['avatar']?:$member['avatar'];
	$info['avatar']=tomedia($info['avatar']);
	$return['member']=$info;
	$is_xieyi=$info['is_xieyi'];
	if(!$is_xieyi && $_SESSION['uid']){
		$return['xieyi']=$this->plugin_setting('siji_xieyi')?:array();
		$return['xieyi']['title']='本平台司机协议';
		$return['show_xieyi']=$return['xieyi']['content']?true:false;
	}
	exi($return);
}
if($_RQ['op']=='set'){
	$postdata=get_postdata();
	if(!$postdata['name']){
		exi('请填写姓名','error');
	}
	if(!$postdata['mobile']){
		exi('请填写手机号','error');
	}
	if(!intval($postdata['mobile']) || strlen($postdata['mobile'])!=11){
		exi('请填写正确手机号','error');
	}
	if(!$postdata['idcard']){
		exi('请填写身份证号','error');
	}
	$data=array(
				'name'=>$postdata['name'],
				'sex'=>$postdata['sex'],
				'mobile'=>$postdata['mobile'],
				'idcard'=>$postdata['idcard'],
				'carid'=>$postdata['carid'],
				'address'=>$postdata['address'],
				'bx'=>$postdata['bx'],
				'cid'=>$postdata['cid'],
				'avatar'=>$postdata['avatar'],
				'codeimg'=>ijson_encode($postdata['codeimg']),
	);
	$info=pdo_get('jy_daijia_driver',array('mid'=>$_SESSION['uid']));
	if($info){
		if($info['idcard']!=$data['idcard'] || $info['mobile']!=$data['mobile'] || $info['carid']!=$data['carid']){
			if($item['shenhe']==1){
				$data['status']=0;
			}else{
				$data['status']=1;
			}
		}
		pdo_update('jy_daijia_driver',$data,array('mid'=>$_SESSION['uid']));
		exi('更新成功！','','/home/');
	}else{
		$data['mid']=$_SESSION['uid'];
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_daijia_driver',$data);
		exi('申请成功！','','/home/');
	}
}
if($_RQ['op']=='set_xieyi'){
	pdo_update('jy_daijia_driver',array('is_xieyi'=>1),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('你已同意本协议！');	
}
?>